<?php
/**
 * Index
 */
include LIB_PATH . '/YAction.class.php';
class IndexAction extends YAction {
    public function index() {
		_404();
		exit;
    }
	
	public function login() {
		
		$this->display();
	}
	
	public function logout() {
		D('Admin')->processLogout();
		
		redirect('/');
	}
	
	public function doLogin() {
		$account = y_getParam('account');
		$password = y_getParam('password');
		$verifyCode = y_getParam('verifyCode');
		
		if(strtolower($verifyCode) != $_SESSION['verifyCode']) {
			$this->error('验证码错误');
			exit;
		}
		
		$admin = D('Admin');
		$rs = $admin->getUserByCondition("username='{$account}'");
		if(empty($rs)) {
			$this->error('用户名或密码错误');
			exit;
		}
		
		if(md5($password) != $rs['password']) {
			$this->error('用户名或密码错误');
			exit;
		}
		
		$admin->saveUserInfo($rs);
		
		redirect(U('Main/index'));
	}
}
